import type {ProColumns} from '@ant-design/pro-components';
import {ProFormInstance, ProTable} from '@ant-design/pro-components';

import {
  loLogin,
  selectFailLoginList,
  chenxingCode,
  cashbroCode,
  cashbroLogin,
  cxLogin,
  merchantList, tigerLogin, dosLogin, papaLogin, okrupeeLogin, prettyloanCode, prettyloanLogin
} from "@/services/bz/api";
import React, {useRef, useState} from "react";
import {Button, Image, message} from "antd";
import {ModalForm, ProFormText, ProForm} from "@ant-design/pro-form/es";
import {useRequest} from "@@/plugin-request/request";

export type TableListItem = {
  merchantCode: string;
  agentCode: string;
  orderNo: string;
  status: number;
  syncStatus: number;
};

export default () => {
  const restFormRef = useRef<ProFormInstance>();
  const formRef = useRef<ProFormInstance>();
  const [modalVisible, setModalVisible] = useState<boolean>(false);
  const [imageVisible, setImageVisible] = useState<boolean>(false);
  const [imageUrl, setImageUrl] = useState<String>("");
  const [papaKey, setPapaKey] = useState<String>("");
  const [merchantData, setMerchantData] = useState({});
  useRequest(merchantList, {
    onSuccess: (res) => {
      let data = {};
      //将拿到的返回值遍历
      res.list.map(item => {
        //使用接口返回值的id做为 代替原本的0，1
        data[item.merchantCode] = {
          //使用接口返回值中的overdueValue属性作为原本的text:后面的值
          text: item.merchantCode,
        };
      });
      setMerchantData(data);
      console.log("===", merchantData)
    },
  });

  const handleOk = (visible, record) => {
    if (visible) {

    }
  };
  const columns: ProColumns<TableListItem>[] = [
    {
      title: 'CID',
      dataIndex: 'cid',
      key: 'cid',
    },
    {
      title: 'Chatter姓名',
      dataIndex: 'chatterName',
      search: false
    },
    {
      title: 'MID',
      dataIndex: 'mid',
    },
    {
      title: 'Model昵称',
      dataIndex: 'modelName',
      search: false
    },
    {
      title: '招呼语',
      dataIndex: 'greeting',
      search: false
    },
    {
      title: '审核状态',
      dataIndex: 'status',
    },
    {
      title: '创建时间',
      dataIndex: 'times',
      search: false
    },
    {
      title: '操作',
      key: 'option',
      width: 250,
      valueType: 'option',
      render: (text, record, _, action) => [
        <a
            type="primary"
            onClick={() => {
              if (record.merchantCode == "littleorange" || record.merchantCode == "chenxing" || record.merchantCode == "cashbro"|| record.merchantCode == "cashbroold"|| record.merchantCode == "prettyloan"|| record.merchantCode == "papamoney"|| record.merchantCode == "papamoney3") {
                setImageVisible(false)
              }else {
                setImageVisible(true)
              }
              setModalVisible(true);
            }}
        >
          审核通过
        </a>,
        <a
            type="primary"
            onClick={() => {
              if (record.merchantCode == "littleorange" || record.merchantCode == "chenxing" || record.merchantCode == "cashbro"|| record.merchantCode == "cashbroold"|| record.merchantCode == "prettyloan"|| record.merchantCode == "papamoney"|| record.merchantCode == "papamoney3") {
                setImageVisible(false)
              }else {
                setImageVisible(true)
              }
              setModalVisible(true);
            }}
        >
          审核拒绝
        </a>
      ]
    }
  ];
  const ref = useRef<ProFormInstance>();
  return (
    <div>
      <ProTable<TableListItem>
        actionRef={ref}
        style={{
          margin: '16px',
        }}
        columns={columns}
        request={async (params: any) => {
          console.log("===", params)
          let code = null;
          if (params.merchantCode != undefined) {
            code = params.merchantCode
          }
          let response = await selectFailLoginList(code);
          console.log(1231, response);
          return {data: response.data == null ? [] : response.data.list};
        }}
        rowKey="key"
        pagination={{
          showSizeChanger: true,
        }}
        search={{
          labelWidth: 'auto',
        }}
        options={false}
        headerTitle=" "
        revalidateOnFocus={false}

      />
    </div>

  );
};
